package dormouse.fx.renderers;

import java.net.URL;

import javafx.scene.Node;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.log4j.Logger;

import dormouse.vfs.ui.renderers.IFileRenderer;

public class WebBrowser extends BorderPane implements IFileRenderer<Node>{
	
	/** Class logger. */
	private static final Logger log = Logger.getLogger(WebBrowser.class);
	
	private static final String[] EXTS = new String[]{"html","htm"};
	
	private WebView webView = new WebView();
	
	/**
	 * Constructor.
	 */
	public WebBrowser(){
		init();
	}

	private void init() {
		setCenter(webView);
		
	}

	@Override
	public void render(FileObject file) {
		URL url = null;
		try {
			url = file.getURL();
			WebEngine webEngine = webView.getEngine();
			webEngine.load(url.toString());
		} catch (FileSystemException e) {
			log.error(e.getMessage(), e);
		}
		
		
	}

	@Override
	public Node getComponent() {
		return this;
	}

	@Override
	public String[] getFileExtensions() {
		return EXTS;
	}

}
